package wsh;

import java.awt.Color;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.JFrame;
import javax.swing.JLabel;

public class denglu {

	public denglu(String name, String password) throws ClassNotFoundException, SQLException {
		// 默认输入的是字符串，所以建议测试的时候输入字符串

		String userID = name;

		String psw1 = password;
		// *代表的是所有列
		String sql2 = "select * from test where 用户名 =" + "'" + userID + "'" + "and 密码=" + "'" + psw1 + "'";
		// 每次新建一个对象，就是新建一个连接connection
		String sql3 = "select 胜场 from test";
		DBHelper dbHelper = new DBHelper();
		DBHelper DBcha = new DBHelper();
		ResultSet rs = DBcha.DB(sql3);
		while (rs.next()) {
			int number = rs.getInt(1);
			bl.sc= number;
			break;
		}
		// 在数据库中查询结果，若结果存在返回登录成功
		ResultSet rsResultSet = dbHelper.DB(sql2);
		if (rsResultSet.next() == true) {
			nmb q = new nmb();
			q.game();
			dbHelper.downConn();
		} else {
	        JFrame f = new JFrame("");
	        f.setSize(400, 150);
	        f.setLocationRelativeTo(null);
	        f.setLayout(null);
	        JLabel l = new JLabel("登录失败，请检查您的用户名和密码是否正确");
	        l.setForeground(Color.red);
	        l.setBounds(50, 50, 300, 30);

	        f.add(l);

	        f.setVisible(true);
			dbHelper.downConn();
		}

	}
}
